web3.js web3.eth.abi.encodeParameter
web3.eth.abi.encodeParameter(type, parameter);
型に基づき、パラメータを ABI 表現にエンコードします。
パラメータ
1. type - String|Object
エンコードするパラメータの型
型のリストについては、Solidity のドキュメント を参照してください。
2. parameter - Mixed
エンコードするパラメータ
戻り値
String
エンコードされた ABI のパラメータ
サンプル
code:example.js
web3.eth.abi.encodeParameter('uint256', '2345675643');
"0x000000000000000000000000000000000000000000000000000000008bd02b7b"
web3.eth.abi.encodeParameter('uint256', '2345675643');
"0x000000000000000000000000000000000000000000000000000000008bd02b7b"
web3.eth.abi.encodeParameter('bytes32', '0xdf3234');
"0xdf32340000000000000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameter('bytes', '0xdf3234');
"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003df32340000000000000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameter('bytes32[]', '0xdf3234', '0xfdfd');
"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002df32340000000000000000000000000000000000000000000000000000000000fdfd000000000000000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameter(
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"childStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
},
{
"propertyOne": 42,
"propertyTwo": 56,
"childStruct": {
"propertyOne": 45,
"propertyTwo": 78
}
}
);
"0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e"
参考
http://web3js.readthedocs.io/en/1.0/web3-eth-abi.html#encodeparameter
#web3.js #web3.js@1.0
web3.js 日本語 API リファレンス